package com.lzq.mq.broker.utils;

/**
 * 字节转换工具类
 */
public class ByteConverUtils {

    /**
     * int转换成字节
     * @param value 待转换的int
     * @return 字节数组
     */
    public static byte[] intToBytes(int value) {
        byte[] src = new byte[4];
        src[3] = (byte) ((value>>24) & 0xFF);
        src[2] = (byte) ((value>>16) & 0xFF);
        src[1] = (byte) ((value>>8) & 0xFF);
        src[0] = (byte) (value & 0xFF);
        return src;
    }

    /**
     * 字节转换成int
     * @param src 字节数组(对前4个字节进行转化)
     * @return  int
     */
    public static int bytesToInt(byte[] src) {
        return ((src[3] & 0xFF) << 24) | ((src[2] & 0xFF) << 16) | ((src[1] & 0xFF) << 8) | (src[0] & 0xFF);
    }
}
